/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.tree.mode;

import java.util.Iterator;

import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;

import twaver.Element;
import twaver.TDataBox;
import twaver.table.TTreeTable;
import twaver.tree.TTree;
import demo.DemoNode;
import demo.DemoNodeFactory;
import demo.DemoPane;

public class TreeSelectionModeDemo extends DemoPane{
	
	public TreeSelectionModeDemo(){
    	JTabbedPane tabbedPane = new JTabbedPane();
    	tabbedPane.add("Tree", createTreeSplitPane());
    	tabbedPane.add("Tree Table", createTreeTableSplitPane());
    	this.add(tabbedPane);
	}
	
	private JSplitPane createTreeSplitPane(){
	    TDataBox box = new TDataBox("Tree Selection Mode Demo");
	    TTree tree = new TTree(box);
	    DemoNodeFactory.createAll(box);
	    JSplitPane split = new JSplitPane(
	    		JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tree), new TreeControlPanel(tree));
	    split.setDividerLocation(200);
	    return split;
	}
	
	private JSplitPane createTreeTableSplitPane(){
		final TDataBox box = new TDataBox("All Demos");	
		DemoNodeFactory.createAll(box);
		
		TTreeTable table = new TTreeTable(box);
		table.setRowHeight(18);
		table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
		table.setElementClass(DemoNode.class);
		table.setTreeColumnDisplayName("Demos");
		TTree tree = table.getTree();
		tree.setRootVisible(false);

		Iterator it = box.iterator();
		while(it.hasNext()){
			Element element = (Element)it.next();
			if(element instanceof DemoNode){
				element.setIcon("/demo/resource/images/file.png");
			}else{
				element.setIcon("/demo/resource/images/folder.png");
			}
		}

		JSplitPane split = new JSplitPane(
				JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table), new TreeControlPanel(tree));
		split.setDividerLocation(400);
		return split;
		
	}
	

}